package ru.niir.goodfil.ui.utils.totalcount;

import ru.niir.goodfil.db.StorageDeliveryStatus;
import ru.niir.goodfil.db.dic.StorageDeliveryState;
import ru.niir.goodfil.utils.SumFormat;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

public class TotalCount {

    public List<DeliveryCount> getTotalDeliveryInfo(List<StorageDeliveryStatus> list){
        List<DeliveryCount> result = new ArrayList<DeliveryCount>();
        DeliveryCount isDelivery = new DeliveryCount();
        DeliveryCount unDelivery = new DeliveryCount();
        for(StorageDeliveryStatus item : list){
            if(item.getDeliveryState() == StorageDeliveryState.IS_DEVERY || item.getDeliveryState() == StorageDeliveryState.IS_CHARGED){
                isDelivery.volume += item.getOrder().getOrderVolume();
                isDelivery.weight += item.getOrder().getOrderWeight();
                isDelivery.sum += item.getOrder().getSum();
                continue;
            }
            else{
                unDelivery.volume += item.getOrder().getOrderVolume();
                unDelivery.weight += item.getOrder().getOrderWeight();
                unDelivery.sum += item.getOrder().getSum();
                continue;
            }
        }
        result.add(isDelivery);
        result.add(unDelivery);
        return result;
    }

    public class DeliveryCount{

        private double volume = 0;

        private double weight = 0;

        private double sum = 0;

        DeliveryCount() {
        }

        public double getVolume() {
            return new BigDecimal(volume).setScale(2, RoundingMode.UP).doubleValue();
        }

        public void setVolume(double volume) {
            this.volume = volume;
        }

        public double getWeight() {
            return new BigDecimal(weight).setScale(2, RoundingMode.UP).doubleValue();
        }

        public void setWeight(double weight) {
            this.weight = weight;
        }

        public double getSum() {
            return new BigDecimal(sum).setScale(2, RoundingMode.UP).doubleValue();
        }

        public String getSumAsString(){
            return SumFormat.formatSum("###,###,##0.00", sum);
        }

        public void setSum(double sum) {
            this.sum = sum;
        }
    }
}
